<%@ page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="../css/style.css"/>
		<script type="text/javascript" src="../js/jquery-1.5.1.min.js"></script>
		<script type="text/javascript" src="../js/uuid.js"></script>
		<script type="text/javascript">
			var id = new UUID();
	$(document).ready(function(){
		$('#vote').click(function(){
			$('#validate').css("display","block");
			$('#show1').css("display","none");
			$('#show2').css("display","block");
			$('#veryCode').focus();
			changeImg();
		});
		
		$('#veryCode').click(function(){
			changeImg();
		});
		
		$('#vote2').click(function(){
			 var code = $("#veryCode").attr("value");   
			 if(code==""){
			 	alert("请输入验证码")
			 	return;
			 }
			code = "c=" + code+"&id="+id;   
		    $.ajax({   
		        type:"POST",   
		        url:"../resultServlet",   
		        data:code,   
		        success:callback   
		    });
		});
		
		
		function callback(data){   
		    //$("#info").html(data);   
		    if(data=="true"){	
		    	var itemId="voteId="+$("#no").text();
			    $.ajax({   
			        type:"POST",  
			        data:itemId, 
			        url:"../VoteServlet",
			        success:function(){
			        	alert("投票成功");
			        	window.location.reload();
			        }
			    });  
		    }else{
		    	alert(data);
		    	window.location.reload();
		    }
		    
		} 
		
	});
		function changeImg(){   
   			var imgSrc = $("#imgObj");   
    		var src = "../validateCodeServlet";   
   			imgSrc.attr("src",chgUrl(src));   
   			
		}   
		//时间戳   
		function chgUrl(url){   
		    var timestamp = (new Date()).valueOf();   
		    url = url.substring(0,22);   
		    if((url.indexOf("&")>=0)){   
		        url = url + "xtamp=" + timestamp;   
		    }else{   
		        url = url + "?timestamp=" + timestamp+"&id="+id;   
		    }   
		    return url;   
		}   

		
		</script>
	</head>
	<body>
		<div class="box1000">
			<div class="main" >
				<div class="sort">
					<h1>
						请投票
					</h1>
					<div >
					<ul class="thumb" >
						<li>
							<a href="#" title="andorid" target="_blank" style="width:200px;">
								<img class="show" id="img1" src="../image/1.jpg" alt="andorid" />
							</a>
							<h2>
								<span>编号：</span><span  id="no" >1</span>
							</h2>
							<h2>
								<span>项目：</span>andorid
							</h2>

							<p><span>网络票数：</span><span id="vote_3504">389</span>票</p>

							<p><span>短信票数：</span>327票</p>
							
							<div id="validate" style="display:none">
							<div  id="codeshow" >
								<img class="vali" id="imgObj" alt="" src=""/>
								<input id="veryCode" name="veryCode" type="text" width="10"/>
							</div>
						    <div id="info"></div> 
							</div>
							<p>
								<a id="vote" style="cursor: hand" href="#"><span id="show1">投一票</span></a>
								<a id="vote2"  style="cursor: hand" href="#"><span id="show2" style="display:none">确认</span></a>
							</p>
						</li>
					</ul>

					</div>
				</div>
			</div>

		</div>

	</body>
</html>
